No Module Named Yum

今早运行Yum报错:

[root@Rony ~]# yum

There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:

   No module named yum

Please install a package which provides this module, or
verify that the module is installed correctly.

It's possible that the above module doesn't match the
current version of Python, which is:
2.7.2 (default, Dec  5 2011, 21:15:46)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)]

If you cannot solve this problem yourself, please go to
the yum faq at:
  http://wiki.linux.duke.edu/YumFaq

错误原因:错误信息描述为 yum 所依赖的python 不相符

查看yum版本

[root@Rony ~]# rpm -qa | grep yum
yum-3.2.22-37.el5.centos
yum-metadata-parser-1.1.2-3.el5.centos
yum-fastestmirror-1.1.16-16.el5.centos

查看python版本

[root@Rony ~]# whereis python

python: /usr/bin/python2.4 /usr/bin/python /usr/lib/python2.4 /usr/local/python2.7 /usr/share/man/man1/python.1.gz

装了两个版本python,因为上次的更新版本到python2.7

执行python,默认使用的是2.7.2的版本

[root@Rony ~]# python
Python 2.7.2 (default, Dec 5 2011, 21:15:46)

[GCC 4.1.2 20080704 (Red Hat 4.1.2-51)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>

yum调用了高版本的python,而yum使用的是python2.4。

查找yum文件,并编辑此py文件

[root@Rony ~]# which yum
/usr/bin/yum
[root@develop local]# vi /usr/bin/yum

将
#!/usr/bin/python
改为:
#!/usr/bin/python2.4

然后保存OK.